home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / zcpp_jae.zip / COMPRESS.C < prev    next >
C/C++ Source or Header  |  1990-07-06  |  1KB  |  54 lines

  1. /*
  2.  
  3.  
  4.  Copyright (C) 1990 Texas Instruments Incorporated.
  5.  
  6.  Permission is granted to any individual or institution to use, copy, modify,
  7.  and distribute this software, provided that this complete copyright and
  8.  permission notice is maintained, intact, in all copies and supporting
  9.  documentation.
  10.  
  11.  Texas Instruments Incorporated provides this software "as is" without
  12.  express or implied warranty.
  13.  
  14.  
  15.  *
  16.  * Edit history
  17.  * Created: LGO 30-Mar-89 -- Initial design and implementation.
  18.  *
  19.  * Simple macro to compress out whitespace
  20.  */
  21.  
  22. #include "defmacio.h"
  23.  
  24. int compress (argc, argv)
  25.      int argc;
  26.      char* argv[];
  27. {
  28.   char c;
  29.   char* body;
  30.   char* bp;
  31.   scan_next(' ');              /* Skip macro name */
  32.   c = skip_blanks();
  33.   if (c != '{') {
  34.     fprintf(stderr, "COMPRESS: Body missing");
  35.     return 1;
  36.   }
  37.   unget();
  38.   body = savestring(scan_next('}'));          /* Grab the macro body */
  39.   while(*body++ != '{');          /* strip start of body */
  40.   bp = body + strlen(body);          /* Strip end of body */
  41.   while(bp > body && *bp != '}') bp--;
  42.   while(bp > body && isspace(*(bp-1))) bp--;
  43.   *bp = EOS;
  44.  
  45.   for (;;) {
  46.     while (isspace(c = *body)) body++;
  47.     while (!isspace(c = *body++)) {
  48.       if (c == EOS) return 0;
  49.       putchar(c);
  50.     }
  51.     putchar(' ');
  52.   }
  53. }
  54.